<?php
/**
 * Description of DemoController
 *
 * @author trunghpb
 */
class DemoController extends fwiSimpleController {
    public function onDef() {
        $this->viewer->viewDef();
    }
    public function onLeave() {
//        echo __FUNCTION__, '<br/>';
    }
    /**
     * this funciton is an event that is loaded before all event
     */
    public function onLoad() {
//        echo __FUNCTION__,'<br/>';
        header("Content-Type: text/html; charset=UTF-8");
    }

    protected function registryTrigger() {
        $this->eventTrigger->createTriggerBefore('onAddStudent', 'initView');
        $this->eventTrigger->createTriggerBefore('onAddStudent', 'initLogic');
        $this->eventTrigger->createTriggerBefore('onListStudent', 'initLogic');
        $this->eventTrigger->createTriggerBefore('onDef', 'initView');
    }

    public function initView() {
        $this->viewer = _fwiload::loadView('DemoView');
    }

    public function initLogic() {
        $this->student = _fwiload::loadLogic('Student');
    }

    public function onAddStudent() {
//        $form = fwiForm::load('DemoForm','frmAddStudent');
//
//        if ($form->isNotValid()) {
//           $this->viewer->warning($form->getMessage());
//        }

//        $this->student->saveData($form->getData());        
        $this->student->saveData($aryData);
        $this->viewer->viewJsonData($paramName);
    }

    public function onListStudent() {
        $condition['member_department_id'] = '10';
        $condition['lastName'] = 'Ha';
        $condition['orderField'] = 'member_family_name';
        $condition['orderDir'] = 'asc';
//        echo '<pre>';
//        var_dump($this->student->findStudent($condition));
        $this->viewer->viewListStudent();
    }
}
?>
